<?php

/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Sitepage
 * @copyright  Copyright 2010-2011 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: Create.php 2011-05-05 9:40:21Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */
class Sitepage_Form_Create extends Engine_Form {
	
	public $_error = array ();
	protected $_packageId;
	
	public function getPackageId() {
		return $this->_packageId;
	}
	
	public function setPackageId($package_id) {
		$this->_packageId = $package_id;
		return $this;
	}
	
	public function init() {
		parent::init ();
		$viewer = Engine_Api::_ ()->user ()->getViewer ();
		$viewer_id = $viewer->getIdentity ();
		$userlevel_id = $viewer->level_id;
		$this->setTitle ( 'Create New Page' )->setDescription ( 'Configure your page to showcase your offerings and connect to your customers.' )->setAction ( Zend_Controller_Front::getInstance ()->getRouter ()->assemble ( array () ) )->setAttrib ( 'name', 'sitepages_create' );
		
		// TITLE
		$this->addElement ( 'Text', 'title', array ('label' => 'Title', 'allowEmpty' => false, 'required' => true, 'filters' => array ('StripTags', new Engine_Filter_Censor (), new Engine_Filter_StringLength ( array ('max' => '63' ) ) ) ) );
		
		// Element: page_url
		$page_id = Zend_Controller_Front::getInstance ()->getRequest ()->getParam ( 'page_id', null );
		if (empty ( $page_id )) {
			$description = Zend_Registry::get ( 'Zend_Translate' )->_ ( 'This will be the end of your page URL. It should be indicative of the title and can contain alphabets, numbers, underscores and  dashes only. Its length should be in the range of 3-255 characters. The complete URL of your page will be: <br /> <span id="page_url_address">http://%s</span>' );
			$description = sprintf ( $description, $_SERVER ['HTTP_HOST'] . Zend_Controller_Front::getInstance ()->getRouter ()->assemble ( array ('page_url' => Zend_Registry::get ( 'Zend_Translate' )->_ ( 'PAGE-NAME' ) ), 'sitepage_entry_view' ) );
			$this->addElement ( 'Text', 'page_url', array ('label' => 'URL', 'description' => $description, 'autocomplete' => 'off', 'required' => true, 'allowEmpty' => false, 'validators' => array (array ('NotEmpty', true ), // array('Alnum', true),
			array ('StringLength', true, array (3, 255 ) ), array ('Regex', true, array ('/^[a-zA-Z0-9-_]+$/' ) ), array ('Db_NoRecordExists', true, array (Engine_Db_Table::getTablePrefix () . 'sitepage_pages', 'page_url' ) ) ) )//'onblur' => 'var el = this; en4.user.checkpage_urlTaken(this.value, function(taken){ el.style.marginBottom = taken * 100 + "px" });'
			 );
			$this->page_url->getDecorator ( 'Description' )->setOptions ( array ('placement' => 'APPEND', 'escape' => false ) );
			$this->page_url->getValidator ( 'NotEmpty' )->setMessage ( 'Please enter a valid page url.', 'isEmpty' );
			$this->page_url->getValidator ( 'Db_NoRecordExists' )->setMessage ( 'Someone has already picked this page url, please use another one.', 'recordFound' );
			$this->page_url->getValidator ( 'Regex' )->setMessage ( 'Profile addresses must start with a letter.', 'regexNotMatch' );
			//$this->page_url->getValidator('Alnum')->setMessage('Profile addresses must be alphanumeric.', 'notAlnum');
			$this->addElement ( 'dummy', 'page_url_msg', array ('value' => 0 ) );
		}
		
		$user = Engine_Api::_ ()->user ()->getViewer ();
		$user_level = Engine_Api::_ ()->user ()->getViewer ()->level_id;
		
		// init to
		$this->addElement ( 'Text', 'tags', array ('label' => 'Tags (Keywords)', 'autocomplete' => 'off', 'description' => 'Separate tags with commas.', 'filters' => array (new Engine_Filter_Censor () ) ) );
		
		$this->tags->getDecorator ( "Description" )->setOption ( "placement", "append" );
		
		// prepare categories
		$categories = Engine_Api::_ ()->getDbTable ( 'categories', 'sitepage' )->getCategories ();
		if (count ( $categories ) != 0) {
			$categories_prepared [0] = "";
			foreach ( $categories as $category ) {
				$categories_prepared [$category->category_id] = $category->category_name;
			}
			
			// category field
			$this->addElement ( 'Select', 'category_id', array ('label' => 'Category', 'allowEmpty' => false, 'required' => true, 'multiOptions' => $categories_prepared, 'onchange' => "subcategory(this.value, '', '');" ) );
		}
		$this->addElement ( 'Select', 'subcategory_id', array ('RegisterInArrayValidator' => false, 'allowEmpty' => true, 'required' => false, 'decorators' => array (array ('ViewScript', array ('viewScript' => 'application/modules/Sitepage/views/scripts/_formSubcategory.tpl', 'class' => 'form element' ) ) ) ) );
		
		$this->addElement ( 'Select', 'subsubcategory_id', array ('RegisterInArrayValidator' => false, 'allowEmpty' => true, 'required' => false, 'decorators' => array (array ('ViewScript', array ('viewScript' => 'application/modules/Sitepage/views/scripts/_formSubcategory.tpl', 'class' => 'form element' ) ) ) ) );
		
		if (Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'sitepage.requried.description', 1 )) {
			// body
			$this->addElement ( 'textarea', 'body', array ('label' => 'Description', 'required' => true, 'allowEmpty' => false, 'attribs' => array ('rows' => 24, 'cols' => 180, 'style' => 'width:300px; max-width:400px;height:120px;' ), 'filters' => array ('StripTags', new Engine_Filter_HtmlSpecialChars (), new Engine_Filter_EnableLinks (), new Engine_Filter_Censor () ) ) );
		} else {
			$this->addElement ( 'textarea', 'body', array ('label' => 'Description', 'attribs' => array ('rows' => 24, 'cols' => 180, 'style' => 'width:300px; max-width:400px;height:120px;' ), 'filters' => array ('StripTags', new Engine_Filter_HtmlSpecialChars (), new Engine_Filter_EnableLinks (), new Engine_Filter_Censor () ) ) );
		}
		
		//$allowed_upload = Engine_Api::_()->authorization()->getPermission($user_level, 'sitepage', 'photo');
		//if ($allowed_upload) {
		if (Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'sitepage.requried.photo', 1 )) {
			$this->addElement ( 'File', 'photo', array ('label' => 'Main Photo', 'required' => true, 'allowEmpty' => false ) );
			$this->photo->addValidator ( 'Extension', false, 'jpg,jpeg,png,gif' );
		} else {
			$this->addElement ( 'File', 'photo', array ('label' => 'Main Photo' ) );
			$this->photo->addValidator ( 'Extension', false, 'jpg,jpeg,png,gif' );
		}
		//}
		// PRICE
		if (Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'sitepage.price.field', 1 )) {
			$localeObject = Zend_Registry::get ( 'Locale' );
			$currencyCode = Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'payment.currency', 'USD' );
			$currencyName = Zend_Locale_Data::getContent ( $localeObject, 'nametocurrency', $currencyCode );
			$this->addElement ( 'Text', 'price', array ('label' => "Price ($currencyName)", // 'description' => '(Zero will make this a free page.)',
			'filters' => array ('StripTags', new Engine_Filter_Censor () ) ) );
		
		//$this->price->getDecorator('Description')->setOption('placement', 'append');
		}
		// LOCATION
		if (Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'sitepage.locationfield', 1 )) {
			$this->addElement ( 'Text', 'location', array ('label' => 'Location', 'description' => 'Eg: Fairview Park, Berkeley, CA', 'filters' => array ('StripTags', new Engine_Filter_Censor () ) ) );
			$this->location->getDecorator ( 'Description' )->setOption ( 'placement', 'append' );
		}
		
		// Privacy
		if (Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'sitepage.manageadmin', 1 ))
			$ownerTitle = "Page Admins";
		else
			$ownerTitle = "Just Me";
		
		$this->addElement ( 'Select', 'all_post', array ('label' => 'Show in Updates Tab', 'multiOptions' => array ("1" => "All Posts", "0" => "Only Posts By Page" ), 'description' => 'Which activities should be shown in Updates Tab?' ) );
		$this->all_post->getDecorator ( 'Description' )->setOption ( 'placement', 'append' );
		
		$availableLabels = array ('everyone' => 'Everyone', 'registered' => 'All Registered Members', 'owner_network' => 'Friends and Networks', 'owner_member_member' => 'Friends of Friends', 'owner_member' => 'Friends Only', 'owner' => $ownerTitle );
		
		// View
		$view_options = ( array ) Engine_Api::_ ()->authorization ()->getAdapter ( 'levels' )->getAllowed ( 'sitepage_page', $user, 'auth_view' );
		$view_options = array_intersect_key ( $availableLabels, array_flip ( $view_options ) );
		
		if (count ( $view_options ) >= 1) {
			$this->addElement ( 'Select', 'auth_view', array ('label' => 'View Privacy', 'description' => 'Who may see this page?', 'multiOptions' => $view_options, 'value' => key ( $view_options ) ) );
			$this->auth_view->getDecorator ( 'Description' )->setOption ( 'placement', 'append' );
		}
		
		// Comment
		$comment_options = ( array ) Engine_Api::_ ()->authorization ()->getAdapter ( 'levels' )->getAllowed ( 'sitepage_page', $user, 'auth_comment' );
		$comment_options = array_intersect_key ( $availableLabels, array_flip ( $comment_options ) );
		
		if (count ( $comment_options ) >= 1) {
			$this->addElement ( 'Select', 'auth_comment', array ('label' => 'Comment Privacy', 'description' => 'Who may post comments on this page?', 'multiOptions' => $comment_options, 'value' => key ( $comment_options ) ) );
			$this->auth_comment->getDecorator ( 'Description' )->setOption ( 'placement', 'append' );
		}
		
		//START PHOTO PRIVACY WORK
		if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagealbum' )) {
			$user = Engine_Api::_ ()->user ()->getViewer ();
			$availableLabels = array ('registered' => 'All Registered Members', 'owner_network' => 'Friends and Networks', 'owner_member_member' => 'Friends of Friends', 'owner_member' => 'Friends Only', 'owner' => $ownerTitle );
			
			$options = ( array ) Engine_Api::_ ()->authorization ()->getAdapter ( 'levels' )->getAllowed ( 'sitepage_page', $user, 'auth_spcreate' );
			$options_create = array_intersect_key ( $availableLabels, array_flip ( $options ) );
			
			if (! empty ( $options_create )) {
				$can_show_list = true;
				if (Engine_Api::_ ()->sitepage ()->hasPackageEnable ()) {
					if (! Engine_Api::_ ()->sitepage ()->allowPackageContent ( $this->getPackageId (), "modules", "sitepagealbum" )) {
						$can_show_list = false;
						$this->addElement ( 'Hidden', 'spcreate', array ('value' => @array_search ( @end ( $options_create ), $options_create ) ) );
					}
				} else {
					$can_create = Engine_Api::_ ()->authorization ()->getPermission ( $userlevel_id, 'sitepage_page', 'spcreate' );
					if (! $can_create) {
						$can_show_list = false;
						$this->addElement ( 'Hidden', 'spcreate', array ('value' => @array_search ( @end ( $options_create ), $options_create ) ) );
					}
				}
				
				if ($can_show_list) {
					$this->addElement ( 'Select', 'spcreate', array ('label' => 'Photo Creation Privacy', 'description' => 'Who may upload photos for this page?', 'multiOptions' => $options_create, 'value' => @array_search ( @end ( $options_create ), $options_create ) ) );
					$this->spcreate->getDecorator ( 'Description' )->setOption ( 'placement', 'append' );
				}
			}
		}
		//END PHOTO PRIVACY WORK
		//START SITEPAGEDOCUMENT PLUGIN WORK
		$sitepageDocumentEnabled = Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagedocument' );
		if ($sitepageDocumentEnabled) {
			$user = Engine_Api::_ ()->user ()->getViewer ();
			
			$availableLabels = array ('registered' => 'All Registered Members', 'owner_network' => 'Friends and Networks', 'owner_member_member' => 'Friends of Friends', 'owner_member' => 'Friends Only', 'owner' => $ownerTitle );
			
			$options = ( array ) Engine_Api::_ ()->authorization ()->getAdapter ( 'levels' )->getAllowed ( 'sitepage_page', $user, 'auth_sdcreate' );
			$options_create = array_intersect_key ( $availableLabels, array_flip ( $options ) );
			
			if (! empty ( $options_create )) {
				$can_show_list = true;
				if (Engine_Api::_ ()->sitepage ()->hasPackageEnable ()) {
					if (! Engine_Api::_ ()->sitepage ()->allowPackageContent ( $this->getPackageId (), "modules", "sitepagedocument" )) {
						$can_show_list = false;
						$this->addElement ( 'Hidden', 'sdcreate', array ('value' => @array_search ( @end ( $options_create ), $options_create ) ) );
					}
				} else {
					$can_create = Engine_Api::_ ()->authorization ()->getPermission ( $userlevel_id, 'sitepage_page', 'sdcreate' );
					if (! $can_create) {
						$can_show_list = false;
						$this->addElement ( 'Hidden', 'sdcreate', array ('value' => @array_search ( @end ( $options_create ), $options_create ) ) );
					}
				}
				if ($can_show_list) {
					$this->addElement ( 'Select', 'sdcreate', array ('label' => 'Documents Creation Privacy', 'description' => 'Who may create documents for this page?', 'multiOptions' => $options_create, 'value' => @array_search ( @end ( $options_create ), $options_create ) ) );
					$this->sdcreate->getDecorator ( 'Description' )->setOption ( 'placement', 'append' );
				}
			}
		}
		//END SITEPAGEDOCUMENT PLUGIN WORK
		//START SITEPAGEVIDEO PLUGIN WORK
		$sitepageVideoEnabled = Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagevideo' );
		if ($sitepageVideoEnabled) {
			$user = Engine_Api::_ ()->user ()->getViewer ();
			
			$availableLabels = array ('registered' => 'All Registered Members', 'owner_network' => 'Friends and Networks', 'owner_member_member' => 'Friends of Friends', 'owner_member' => 'Friends Only', 'owner' => $ownerTitle );
			
			$options = ( array ) Engine_Api::_ ()->authorization ()->getAdapter ( 'levels' )->getAllowed ( 'sitepage_page', $user, 'auth_svcreate' );
			$options_create = array_intersect_key ( $availableLabels, array_flip ( $options ) );
			
			if (! empty ( $options_create )) {
				$can_show_list = true;
				if (Engine_Api::_ ()->sitepage ()->hasPackageEnable ()) {
					if (! Engine_Api::_ ()->sitepage ()->allowPackageContent ( $this->getPackageId (), "modules", "sitepagevideo" )) {
						$can_show_list = false;
						$this->addElement ( 'Hidden', 'svcreate', array ('value' => @array_search ( @end ( $options_create ), $options_create ) ) );
					}
				} else {
					$can_create = Engine_Api::_ ()->authorization ()->getPermission ( $userlevel_id, 'sitepage_page', 'svcreate' );
					if (! $can_create) {
						$can_show_list = false;
						$this->addElement ( 'Hidden', 'svcreate', array ('value' => @array_search ( @end ( $options_create ), $options_create ) ) );
					}
				}
				if ($can_show_list) {
					$this->addElement ( 'Select', 'svcreate', array ('label' => 'Videos Creation Privacy', 'description' => 'Who may create videos for this page?', 'multiOptions' => $options_create, 'value' => @array_search ( @end ( $options_create ), $options_create ) ) );
					$this->svcreate->getDecorator ( 'Description' )->setOption ( 'placement', 'append' );
				}
			}
		}
		//END SITEPAGEVIDEO PLUGIN WORK
		//START SITEPAGEPOLL PLUGIN WORK
		$sitepagePollEnabled = Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagepoll' );
		if ($sitepagePollEnabled) {
			$user = Engine_Api::_ ()->user ()->getViewer ();
			
			$availableLabels = array ('registered' => 'All Registered Members', 'owner_network' => 'Friends and Networks', 'owner_member_member' => 'Friends of Friends', 'owner_member' => 'Friends Only', 'owner' => $ownerTitle );
			
			$options = ( array ) Engine_Api::_ ()->authorization ()->getAdapter ( 'levels' )->getAllowed ( 'sitepage_page', $user, 'auth_splcreate' );
			$options_create = array_intersect_key ( $availableLabels, array_flip ( $options ) );
			
			if (! empty ( $options_create )) {
				$can_show_list = true;
				if (Engine_Api::_ ()->sitepage ()->hasPackageEnable ()) {
					if (! Engine_Api::_ ()->sitepage ()->allowPackageContent ( $this->getPackageId (), "modules", "sitepagepoll" )) {
						$can_show_list = false;
						$this->addElement ( 'Hidden', 'splcreate', array ('value' => @array_search ( @end ( $options_create ), $options_create ) ) );
					}
				} else {
					$can_create = Engine_Api::_ ()->authorization ()->getPermission ( $userlevel_id, 'sitepage_page', 'splcreate' );
					if (! $can_create) {
						$can_show_list = false;
						$this->addElement ( 'Hidden', 'splcreate', array ('value' => @array_search ( @end ( $options_create ), $options_create ) ) );
					}
				}
				if ($can_show_list) {
					$this->addElement ( 'Select', 'splcreate', array ('label' => 'Polls Creation Privacy', 'description' => 'Who may create polls for this page?', 'multiOptions' => $options_create, 'value' => @array_search ( @end ( $options_create ), $options_create ) ) );
					$this->splcreate->getDecorator ( 'Description' )->setOption ( 'placement', 'append' );
				}
			}
		}
		//END SITEPAGEPOLL PLUGIN WORK
		//START SITEPAGENOTE PLUGIN WORK
		$sitepageNoteEnabled = Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagenote' );
		if ($sitepageNoteEnabled) {
			$user = Engine_Api::_ ()->user ()->getViewer ();
			
			$availableLabels = array ('registered' => 'All Registered Members', 'owner_network' => 'Friends and Networks', 'owner_member_member' => 'Friends of Friends', 'owner_member' => 'Friends Only', 'owner' => $ownerTitle );
			
			$options = ( array ) Engine_Api::_ ()->authorization ()->getAdapter ( 'levels' )->getAllowed ( 'sitepage_page', $user, 'auth_sncreate' );
			$options_create = array_intersect_key ( $availableLabels, array_flip ( $options ) );
			
			if (! empty ( $options_create )) {
				$can_show_list = true;
				if (Engine_Api::_ ()->sitepage ()->hasPackageEnable ()) {
					if (! Engine_Api::_ ()->sitepage ()->allowPackageContent ( $this->getPackageId (), "modules", "sitepagenote" )) {
						$can_show_list = false;
						$this->addElement ( 'Hidden', 'sncreate', array ('value' => @array_search ( @end ( $options_create ), $options_create ) ) );
					}
				} else {
					$can_create = Engine_Api::_ ()->authorization ()->getPermission ( $userlevel_id, 'sitepage_page', 'sncreate' );
					if (! $can_create) {
						$can_show_list = false;
						$this->addElement ( 'Hidden', 'sncreate', array ('value' => @array_search ( @end ( $options_create ), $options_create ) ) );
					}
				}
				if ($can_show_list) {
					$this->addElement ( 'Select', 'sncreate', array ('label' => 'Notes Creation Privacy', 'description' => 'Who may create notes for this page?', 'multiOptions' => $options_create, 'value' => @array_search ( @end ( $options_create ), $options_create ) ) );
					$this->sncreate->getDecorator ( 'Description' )->setOption ( 'placement', 'append' );
				}
			}
		}
		//END SITEPAGENOTE PLUGIN WORK
		//START SITEPAGEEVENT PLUGIN WORK
		$sitepageEventEnabled = Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepageevent' );
		if ($sitepageEventEnabled) {
			$user = Engine_Api::_ ()->user ()->getViewer ();
			
			$availableLabels = array ('registered' => 'All Registered Members', 'owner_network' => 'Friends and Networks', 'owner_member_member' => 'Friends of Friends', 'owner_member' => 'Friends Only', 'owner' => $ownerTitle );
			
			$options = ( array ) Engine_Api::_ ()->authorization ()->getAdapter ( 'levels' )->getAllowed ( 'sitepage_page', $user, 'auth_secreate' );
			$options_create = array_intersect_key ( $availableLabels, array_flip ( $options ) );
			
			if (! empty ( $options_create )) {
				$can_show_list = true;
				if (Engine_Api::_ ()->sitepage ()->hasPackageEnable ()) {
					if (! Engine_Api::_ ()->sitepage ()->allowPackageContent ( $this->getPackageId (), "modules", "sitepageevent" )) {
						$can_show_list = false;
						$this->addElement ( 'Hidden', 'secreate', array ('value' => @array_search ( @end ( $options_create ), $options_create ) ) );
					}
				} else {
					$can_create = Engine_Api::_ ()->authorization ()->getPermission ( $userlevel_id, 'sitepage_page', 'secreate' );
					if (! $can_create) {
						$can_show_list = false;
						$this->addElement ( 'Hidden', 'secreate', array ('value' => @array_search ( @end ( $options_create ), $options_create ) ) );
					}
				}
				if ($can_show_list) {
					$this->addElement ( 'Select', 'secreate', array ('label' => 'Event Creation Privacy', 'description' => 'Who may create events for this page?', 'multiOptions' => $options_create, 'value' => @array_search ( @end ( $options_create ), $options_create ) ) );
					$this->secreate->getDecorator ( 'Description' )->setOption ( 'placement', 'append' );
				}
			}
		}
		//END SITEPAGEEVENT PLUGIN WORK
		//START SITEPAGEMUSIC PLUGIN WORK
		$sitepageMusicEnabled = Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagemusic' );
		if ($sitepageMusicEnabled) {
			$user = Engine_Api::_ ()->user ()->getViewer ();
			
			$availableLabels = array ('registered' => 'All Registered Members', 'owner_network' => 'Friends and Networks', 'owner_member_member' => 'Friends of Friends', 'owner_member' => 'Friends Only', 'owner' => $ownerTitle );
			
			$options = ( array ) Engine_Api::_ ()->authorization ()->getAdapter ( 'levels' )->getAllowed ( 'sitepage_page', $user, 'auth_smcreate' );
			$options_create = array_intersect_key ( $availableLabels, array_flip ( $options ) );
			
			if (! empty ( $options_create )) {
				$can_show_list = true;
				if (Engine_Api::_ ()->sitepage ()->hasPackageEnable ()) {
					if (! Engine_Api::_ ()->sitepage ()->allowPackageContent ( $this->getPackageId (), "modules", "sitepagemusic" )) {
						$can_show_list = false;
						$this->addElement ( 'Hidden', 'smcreate', array ('value' => @array_search ( @end ( $options_create ), $options_create ) ) );
					}
				} else {
					$can_create = Engine_Api::_ ()->authorization ()->getPermission ( $userlevel_id, 'sitepage_page', 'smcreate' );
					if (! $can_create) {
						$can_show_list = false;
						$this->addElement ( 'Hidden', 'smcreate', array ('value' => @array_search ( @end ( $options_create ), $options_create ) ) );
					}
				}
				if ($can_show_list) {
					$this->addElement ( 'Select', 'smcreate', array ('label' => 'Music Creation Privacy', 'description' => 'Who may upload music for this page?', 'multiOptions' => $options_create, 'value' => @array_search ( @end ( $options_create ), $options_create ) ) );
					$this->smcreate->getDecorator ( 'Description' )->setOption ( 'placement', 'append' );
				}
			}
		}
		//END SITEPAGEMUSIC PLUGIN WORK
		//NETWORK BASE PAGE VIEW PRIVACY
		if (Engine_Api::_ ()->getApi ( 'subCore', 'sitepage' )->pageBaseNetworkEnable ()) {
			// Make Network List
			$table = Engine_Api::_ ()->getDbtable ( 'networks', 'network' );
			$select = $table->select ()->from ( $table->info ( 'name' ), array ('network_id', 'title' ) )->where ( '	hide = ?', 0 )->order ( 'title' );
			$result = $table->fetchAll ( $select );
			
			$networksOptions = array ('0' => 'Everyone' );
			foreach ( $result as $value ) {
				$networksOptions [$value->network_id] = $value->title;
			}
			if (count ( $networksOptions ) > 0) {
				$this->addElement ( 'Multiselect', 'networks_privacy', array ('label' => 'Networks Selection', 'description' => 'Select the networks, members of which should be able to see your page. (Press Ctrl and click to select multiple networks. You can also choose to make your page viewable to everyone.)', //            'attribs' => array('style' => 'max-height:150px; '),
				'multiOptions' => $networksOptions, 'value' => array (0 ) ) );
			}
		}
		
		$table = Engine_Api::_ ()->getDbtable ( 'listmemberclaims', 'sitepage' );
		$select = $table->select ()->where ( 'user_id = ?', $viewer_id )->limit ( 1 );
		
		$row = $table->fetchRow ( $select );
		if ($row !== null) {
			$this->addElement ( 'Checkbox', 'userclaim', array ('label' => 'Show "Claim this Page" link on this page.', 'value' => 1 ) );
		}
		$this->addElement ( 'Select', 'draft', array ('label' => 'Status', 'multiOptions' => array ("1" => "Published", "0" => "Saved As Draft" ), 'description' => 'If this entry is published, it cannot be switched back to draft mode.', 'onchange' => 'checkDraft();' ) );
		$this->draft->getDecorator ( 'Description' )->setOption ( 'placement', 'append' );
		$this->addElement ( 'Checkbox', 'search', array ('label' => "Show this page in search results.", 'value' => 1 ) );
		
		// Element: execute
		$this->addElement ( 'Button', 'execute', array ('label' => 'Create', 'type' => 'submit', 'ignore' => true, 'decorators' => array ('ViewHelper' ) ) );
		
		// Element: cancel
		$this->addElement ( 'Cancel', 'cancel', array ('label' => 'cancel', 'link' => true, 'prependText' => ' or ', 'href' => Zend_Controller_Front::getInstance ()->getRouter ()->assemble ( array ('action' => 'manage' ), 'sitepage_general', true ), 'decorators' => array ('ViewHelper' ) ) );
		
		// DisplayGroup: buttons
		$this->addDisplayGroup ( array ('execute', 'cancel' ), 'buttons', array ('decorators' => array ('FormElements', 'DivDivDivWrapper' ) ) );
	}

}
?>